//
//  WBTabBarController.swift
//  weiboD
//
//  Created by gao2015 on 2016/11/30.
//  Copyright © 2016年 gao2015. All rights reserved.
//

import UIKit

class WBTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let wbTabBar = WBTabBar();
        
//        wbTabBar.callBack = {[weak self] in
//        
////            print(self)
//        
//        }
        //设置代理
        wbTabBar.newdelegate = self
        
        //只读属性只能通过kvc赋值
        setValue(wbTabBar, forKey: "tabBar")
        

        //创建4个控制器
        addChildViewController(childController: WBHomeController(), title: "主页", imageName: "tabbar_home")
        addChildViewController(childController: WBMessageController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(childController: WBDiscoverController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(childController: WBProfileController(), title: "我的", imageName: "tabbar_profile")
        
        
        // Do any additional setup after loading the view.
    }

        //重载创建子控制器的方法来创建子控制器
    func addChildViewController(childController: UIViewController,title:String,imageName:String) {
        //统一设置tabBar顶部与顶部标题
        childController.title = title
        //设置未选中图片
        childController.tabBarItem.image = UIImage(named: imageName)
        //设置选中的图片,并原始渲染
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        //设置选中状态的颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        //设置字体大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 12)], for: .normal)
        
        //嵌套一个导航控制器
        let nav = WBNavController(rootViewController: childController)
        //添加到tabBar上
        addChildViewController(nav)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}

//MARK:--自定义代理的扩展

extension WBTabBarController: WBTabBarDelegate{
    func didSelectAddBtn() {
        print("代理过来的方法")
    }

}
